<script LANGUAGE="javascript">
<!--
function verificarSalvar() 
{ 
  var theCPF = document.formulario.clie_cpf_cnpj;
  if (theCPF.value == "") 
  { 
    alert("Preencha o campo CPF/CNPJ");
    theCPF.focus();
    return (false);
  } 
  if (((theCPF.value.length == 11) && (theCPF.value == 11111111111) || (theCPF.value == 22222222222) || (theCPF.value == 33333333333) || (theCPF.value == 44444444444) || (theCPF.value == 55555555555) || (theCPF.value == 66666666666) || (theCPF.value == 77777777777) || (theCPF.value == 88888888888) || (theCPF.value == 99999999999) || (theCPF.value == 00000000000))) 
  { 
    alert("CPF/CNPJ inválido. Por favor, preencha novamente o campo.");
    theCPF.focus();
    return (false);
  } 


  if (!((theCPF.value.length == 11) || (theCPF.value.length == 14))) 
  { 
    alert("CPF/CNPJ inválido. Por favor, preencha novamente o campo.");
    theCPF.focus();
    return (false); 
  } 

  var checkOK = "0123456789";
  var checkStr = theCPF.value;
  var allValid = true;
  var allNum = "";
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
    allNum += ch;
  } 
  if (!allValid) 
  {
    alert("Favor preencher somente com dígitos o campo CPF/CNPJ.");
    theCPF.focus();
    return (false);
  }

  var chkVal = allNum;
  var prsVal = parseFloat(allNum);
  if (chkVal != "" && !(prsVal > "0"))
  {
    alert("CPF zerado. Por favor, preencha novamente o campo.");
    theCPF.focus();
    return (false);
  }

if (theCPF.value.length == 11)
{
  var tot = 0;
  for (i = 2;  i <= 10;  i++)
    tot += i * parseInt(checkStr.charAt(10 - i));
  if ((tot * 10 % 11 % 10) != parseInt(checkStr.charAt(9)))
  {
    alert("CPF/CNPJ inválido. Por favor, preencha novamente o campo.");
    theCPF.focus();
    return (false);
  }
 
  tot = 0;
  
  for (i = 2;  i <= 11;  i++)
    tot += i * parseInt(checkStr.charAt(11 - i));

  if ((tot * 10 % 11 % 10) != parseInt(checkStr.charAt(10)))
  {
    alert("CPF/CNPJ inválido. Por favor, preencha novamente o campo.");
    theCPF.focus();
    return (false);
  }
}
else
{
  var tot  = 0;
  var peso = 2;
  
  for (i = 0;  i <= 11;  i++)
  {
    tot += peso * parseInt(checkStr.charAt(11 - i));
    peso++;
    if (peso == 10)
    {
        peso = 2;
    }
  }

  if ((tot * 10 % 11 % 10) != parseInt(checkStr.charAt(12)))
  {
    alert("CPF/CNPJ inválido. Por favor, preencha novamente o campo.");
    theCPF.focus();
    return (false);
  }
 
  tot  = 0;
  peso = 2;
  
  for (i = 0;  i <= 12;  i++)
  {
    tot += peso * parseInt(checkStr.charAt(12 - i)) 
    peso++;
    if (peso == 10)
    {
        peso = 2;
    }
  }
  if ((tot * 10 % 11 % 10) != parseInt(checkStr.charAt(13)))
  {
    alert("CPF/CNPJ inválido. Por favor, preencha novamente o campo.");
    theCPF.focus();
    return (false);
  }
}
 // return(true);
}
//-->
</script>
<?php echo $html->script('validar'); ?>
<div class="wrapper">
    <br><br>
    <div class="leadsCtn">
        <div class="title">
                <h4 class="left">Novo cliente</h4>
        </div>
        <div class="content bMargin-7">                    
            <form name="formulario" method="post" action="<?php echo Mapper::url('/cliente/adicionar'); ?>">
                <fieldset class="left">
                    <ul class="form vhh a">
                        <li>
                            <label>Nome:</label>
                            <input type="text" name="clie_nome" class="required" label="Nome" value=""/>
                        </li>
                        <li>
                            <label>Login administrador:</label>
                            <input type="text" name="usua_chave" class="required" label="Login administrador" value=""/>
                        </li>
                        <li>
                            <label>Senha:</label>
                            <input type="text" name="usua_senha" class="required" label="Senha" value="<?php echo $sUsuaSenha; ?>"/>
                        </li>
                        <li>
                            <label>E-mail:</label>
                            <input type="text" name="clie_email" class="email" label="E-mail" value=""/>
                        </li>
                        <li>
                            <label>Telefone:</label>
                            <input type="text" name="clie_telefone" class="telefone" label="Telefone" value=""/>
                        </li>
                        <li class="bMargin-7">
                            <label>Celular:</label>
                            <input type="text" name="clie_celular" class="telefone" label="Celular" value=""/>
                        </li>
                        <li>
                            <label>Empresa:</label>
                            <input type="text" name="clie_empresa" class="required"  label="Empresa" value=""/>
                        </li>
                        <li>
                            <label>CPF/CNPJ:</label>
                            <input type="text" name="clie_cpf_cnpj" class="required" label="CPF/CNPJ" value=""/>
                        </li>
                        <li>
                            <label for="">Endereço:</label>
                            <input type="text" name="clie_endereco" class="required" label="Endereço" value=""/>
                        </li>
                        <li>
                            <label>Cidade:</label>
                            <input type="text" name="clie_cidade" class="required" label="Cidade" value=""/>
                        </li>
                        <li>
                            <label>Estado:</label>
                            <select name="clie_estado">
                                <option value="AC">Acre</option>
                                <option value="AL">Alagoas</option>
                                <option value="AP">Amapá</option>
                                <option value="AM">Amazonas</option>
                                <option value="BA">Bahia</option>
                                <option value="CE">Ceará</option>
                                <option value="DF">Distrito Federal</option>
                                <option value="ES">Espírito Santo</option>
                                <option value="GO">Goiás</option>
                                <option value="MA">Maranhão</option>
                                <option value="MT">Mato Grosso</option>
                                <option value="MS">Mato Grosso do Sul</option>
                                <option value="MG" selected ="selected">Minas Gerais</option>
                                <option value="PA">Pará</option>
                                <option value="PB">Paraíba</option>
                                <option value="PR">Paraná</option>
                                <option value="PE">Pernambuco</option>
                                <option value="PI">Piauí</option>
                                <option value="RJ">Rio de Janeiro</option>
                                <option value="RN">Rio Grande do Norte</option>
                                <option value="RS">Rio Grande do Sul</option>
                                <option value="RO">Rondônia</option>
                                <option value="RR">Roraima</option>
                                <option value="SC">Santa Catarina</option>
                                <option value="SP">São Paulo</option>
                                <option value="SE">Sergipe</option>
                                <option value="TO">Tocantins</option>
                            </select>
                        </li>
                    </ul>
                </fieldset>
                <fieldset class="right">
                    <ul class="form b right">
                        <?php /*
                        <li>
                                <label for="">Plano:</label>
                                <input type="text" name="clie_plano" value="" />
                        </li>
                        <li>
                                <label for="">Valor do plano:</label>
                                <input type="text" name="clie_valor" value="" />
                        </li>
                        <li>
                                <label for="">Nº Usuários:</label>
                                <input type="text" name="clie_max_usua" value="" />
                        </li>
                        <li>
                                <label for="">Qtd. Leads:</label>
                                <input type="text" name="clie_max_lead" value="" />
                        </li>
                        <li>
                                <label for="">Qtd. Campanhas:</label>
                                <input type="text" name="clie_max_camp" value="" />
                        </li>
                        * */?>
                        <li>
                            <label>Plano:</label>
                            <select name="plan_id" class="left" size="1">
                            <?php
                               foreach($arrPlano as $objPlano)
                               {
                                   $objPlano = (object) $objPlano;
                                   echo '<option value="'.$objPlano->plan_id.'">'.$objPlano->plan_nome.' de valor R$'.$objPlano->plan_valor.',00</option>';
                               }
                           ?>
                           </select>
                        </li>
                        <li>
                            <label>Empresa de acesso:</label>
                            <input type="text" name="clie_url_acesso" label="Empressa de acesso" class="required" value=""/>
                        </li>
                        <li>
                            <label>Status:</label>
                            <select name="clie_status" class="left">
                                <option value="1" selected="selected">Ativo</option>
                                <option value="0">Inativo</option>
                                <option value="2">Excluido</option>
                            </select>
                        </li>
                    </ul>
                    <?php
                    /* VER REGRA 
                    <ul class="form hhh bMargin-3 right">
                        <li>
                            <input type="radio" name="" value="" />
                            <label type="text" for="">Test Drive 7 dias</label>
                        </li>
                        <li>
                            <input type="radio" name="" value="" />
                            <label type="text" for="">Test Drive 15 dias</label>
                        </li>
                        <li>
                            <input type="radio" name="" value="" />
                            <label type="text" for="">Test Drive 30 dias</label>
                        </li>
                    </ul>
                     <ul class="form hhh tar c right bMargin-3">
                        <li>
                            <label for="">Início</label>
                            <input type="text" name="clie_data_inicio" value="" />
                        </li>
                        <li>
                            <label for="">Término</label>
                            <input type="text" name="clie_data_fim" value="" />
                        </li>
                    </ul>
                    */
                    ?>					
                    <div class="clear"></div>
                    <input type="submit" class="right botaoCinza" value="Salvar" onmousedown="verificarSalvar()"/>
                </fieldset>
            </form>
        </div><!-- .content -->
    </div><!-- .leads -->
</div><!-- .wraper -->